using UnityEngine;
using System.Collections;

public class TopScore : MonoBehaviour {

	GameSaveLoad _saveLoad;
	GameData _gameData;
	public UILabel[] Topscores;
	
	void Start () {
		
	}
	
	void OnEnable(){
		if(_saveLoad==null)
		_saveLoad = new GameSaveLoad();
		_gameData = _saveLoad.Load();
		if(_gameData==null){
			_gameData=new GameData();
		}
		_gameData.TopScores.Add(GameController.Instance.GetScore());
		_gameData.TopScores.Sort();
		_gameData.TopScores.Reverse();
		if(_gameData.TopScores.Count>5){
			_gameData.TopScores.RemoveRange(5, _gameData.TopScores.Count-5);
		}
		for(int i=0; i<_gameData.TopScores.Count;i++){
			Topscores[i].text = _gameData.TopScores[i].ToString();
		}
		_saveLoad.Save(_gameData);
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
